# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from django.http import  HttpResponseRedirect
from django.shortcuts import render_to_response
from export.b2b.ugcontract import Ugcontract
from export.importIntoMagento import ImportIntoMagento
from export.services import UploadCatalog

def view(request):
    """

    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))
    if request.user.is_superuser:
        form = UploadCatalog(request.POST, request.FILES)
        if form.is_valid():
        #            form.getProduct()
            magento = ImportIntoMagento().importProducts(form.getProduct())
        else:
            form = UploadCatalog()
        return render_to_response('export/view.html', {'form': form})
    return HttpResponseRedirect(reverse('home'))


def convert(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))
    if request.user.is_superuser:
        if request.method == 'POST':
            if request.FILES:
                if request.FILES.has_key('file'):
                    fileContent = request.FILES['file']
        form = UploadCatalog()
        return render_to_response('export/view.html', {'form': form})
    return HttpResponseRedirect(reverse('home'))


def price(request):
    return render_to_response('export/price.html')